// 导入axios.js
import instance from '@/utils/axios.js'

// 封装查询所有文章类别接口函数
function getArticleCategory () {
  return instance({
    url: '/admin/category/list',
    method: 'get'
  })
}

// 封装新增文章类别接口函数
function addArticleCategory ({ name, slug }) {
  return instance({
    url: '/admin/category/add',
    method: 'post',
    data: {
      name,
      slug
    }
  })
}

// 封装编辑文章类别接口函数
function editArticleCategory ({ id, name, slug }) {
  return instance({
    url: '/admin/category/edit',
    method: 'post',
    data: { id, name, slug }
  })
}

// 封装删除文章类别接口函数
function deleteArticleCategory (id) {
  return instance({
    url: '/admin/category/delete',
    method: 'post',
    data: { id }
  })
}

// 导出接口
export {
  getArticleCategory,
  addArticleCategory,
  editArticleCategory,
  deleteArticleCategory
}

// 封装获取全部文章接口函数
function getArticleList (obj) {
  return instance({
    url: '/admin/article/query',
    method: 'get',
    params: obj
  })
}

// 封装新增文章接口函数
function addArticle (obj) {
  return instance({
    url: '/admin/article/publish',
    method: 'post',
    data: obj
  })
}

// 封装修改文章接口函数
function editArticle (obj) {
  return instance({
    url: '/admin/article/edit',
    method: 'post',
    data: obj
  })
}

// 封装删除文章接口函数
function deleteArticle (id) {
  return instance({
    url: '/admin/article/delete',
    method: 'post',
    data: { id }
  })
}

// 导出接口
export { getArticleList, addArticle, editArticle, deleteArticle }

//根据id获取文章信息
const searcharticleList = id => {
  return instance({
      url: '/admin/article/search',
      method: 'get',
      params: { id }
  })
}
export { searcharticleList }